AC_PREREQ([2.69])

m4_define([bolt_major_version], [1])
m4_define([bolt_minor_version], [0])
m4_define([bolt_impl_version], [0])
m4_define([bolt_impl_fix], [0])

m4_define([bolt_version], [bolt_major_version.bolt_minor_version.bolt_impl_version])
m4_define([bolt_lib_version], [bolt_major_version:bolt_minor_version:bolt_impl_version])

AC_INIT([bolt], [bolt_version], [], [], [https://gitee.com/caikov/bolt.git])

BOLT_MAJOR_VERSION=bolt_major_version
AC_SUBST(BOLT_MAJOR_VERSION)

BOLT_MINOR_VERSION=bolt_minor_version
AC_SUBST(BOLT_MINOR_VERSION)

BOLT_IMPL_VERSION=bolt_impl_version
AC_SUBST(BOLT_IMPL_VERSION)

BOLT_VERSION=bolt_version
AC_SUBST(BOLT_VERSION)

BOLT_LIBSO_VERSION=bolt_lib_version
AC_SUBST(BOLT_LIBSO_VERSION)

AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror])
AC_CONFIG_SRCDIR([include/bolt.h])
AC_CONFIG_HEADERS([config.h])

AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AM_PROG_CC_C_O
AM_PROG_AR

AC_SUBST([LIBTOOL_DEPS])
AM_PROG_LIBTOOL

PKG_PROG_PKG_CONFIG

AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T

BOLT_CFLAGS="$BOLT_CFLAGS -W -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes"
BOLT_CFLAGS="$BOLT_CFLAGS -Wmissing-declarations -Wold-style-definition -Wpointer-arith"
BOLT_CFLAGS="$BOLT_CFLAGS -Wcast-align -Wnested-externs -Wcast-qual -Wformat-nonliteral"
BOLT_CFLAGS="$BOLT_CFLAGS -Wformat-security -Wundef -Wwrite-strings"
BOLT_CFLAGS="$BOLT_CFLAGS -std=c99"

# Extra flags for example to suppress certain warning types
BOLT_CFLAGS="$BOLT_CFLAGS $BOLT_CFLAGS_EXTRA"

BOLT_CPPFLAGS="$BOLT_CPPFLAGS"

AM_CFLAGS="$AM_CFLAGS $BOLT_CFLAGS"
AM_CXXFLAGS="-std=c++11"
AM_CPPFLAGS="$AM_CPPFLAGS $BOLT_CPPFLAGS"

AC_CONFIG_FILES([
  Makefile
  src/Makefile
  example/Makefile
])

AC_ARG_WITH(config_path, [--with-config-path=PATH for config],  
  BOLT_CONFIG_PATH=$withval, BOLT_CONFIG_PATH=${sysconfdir}/bolt)
AC_SUBST(BOLT_CONFIG_PATH)

AC_CHECK_PROGS([PKGCONFIG], [pkg-config])
if test -z "$PKGCONFIG"; then
	AC_MSG_ERROR([Please install pkg-config])
fi

if test $enable_static = "yes" ; then
	export PKG_CONFIG="pkg-config --static"
fi

PKG_CHECK_MODULES([EL], [libel])
AC_SUBST([EL_CFLAGS])
AC_SUBST([EL_LIBS])

AM_CONDITIONAL([HAVE_PKGCONFIG], [test -n "$PKGCONFIG"])
AM_COND_IF([HAVE_PKGCONFIG], [AC_CONFIG_FILES([pkgconfig/Makefile])])
AM_COND_IF([HAVE_PKGCONFIG], [AC_CONFIG_FILES([pkgconfig/libbolt.pc])])

AC_SUBST([LIBS])
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

CC_VERSION=$($CC --version | head -n 1)

AC_OUTPUT

AC_MSG_RESULT([
	$PACKAGE $VERSION
	=================
	BOLT version:		  ${BOLT_VERSION}
	Library version:	${BOLT_LIBSO_VERSION}

	host:			        ${host}
	prefix:			      ${prefix}
	sysconfdir:		    ${sysconfdir}
	libdir:			      ${libdir}
	includedir:		    ${includedir}

	cc:			          ${CC}
	cc version:		    ${CC_VERSION}
	cppflags:		      ${CPPFLAGS}
	am_cppflags:		  ${AM_CPPFLAGS}
	cflags:			      ${CFLAGS}
	am_cflags:		    ${AM_CFLAGS}
	am_cxxflags:		  ${AM_CXXFLAGS}
	ldflags:		      ${LDFLAGS}
	am_ldflags:		    ${AM_LDFLAGS}
	])



  
  
